home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 May: Tool Chest / Dev.CD May 97 TC.toast / Sample Code / Snippets / QuickDraw / MakeIcon / OldBitMap.c < prev    next >
Encoding:
Text File  |  1992-07-15  |  2.2 KB  |  69 lines  |  [TEXT/KAHL]

  1.  
  2. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3.  
  4.     old-style bitmap utility routines for allocating, de-allocating, and masking.
  5.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  6.  
  7.  
  8. void FreeBitMap(BitMap *Bits)
  9. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  10.     Dumps a BitMap created by NewBitMap below.
  11.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  12. {
  13.     DisposPtr(Bits->baseAddr);
  14.     Bits->baseAddr=NIL;
  15.     SetRect(&Bits->bounds,0,0,0,0);
  16.     Bits->rowBytes=0;
  17. }
  18.  
  19. void CalcOffScreen(register Rect *frame,register long *needed, register short *rows)
  20. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21.     Calculates how much memory and rowbytes a bitmap of the size frame would require.
  22.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  23. {
  24.     *rows=((((frame->right) - (frame->left)) + 15)/16) *2;
  25.     *needed=(((long)(*rows)) * (long)((frame->bottom) - (frame->top)));
  26. }
  27.  
  28. void NewBitMap(Rect *frame,BitMap *theMap)
  29. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  30.     Creates a new empty bitmap.
  31.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  32. {
  33.     Size    size;
  34.     int        rbytes;
  35.     
  36.     CalcOffScreen(frame,&size,&rbytes);
  37.     
  38.     theMap->rowBytes=rbytes;
  39.     theMap->bounds=*frame;
  40.     theMap->baseAddr=NewPtrClear(size);
  41. }
  42.  
  43.  
  44. void NewMaskedBitMap(BitMap    *srcBits, BitMap *maskBits, Rect *srcRect)
  45. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  46.     Pass a pointer to an existing bitmap, and this creates a bitmap that is an
  47.     equivelent mask.
  48.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  49. {
  50.     short    rowbytes,height,words;
  51.     long    needed;
  52.  
  53.     NewBitMap(srcRect,maskBits);
  54.     
  55.     if(MemErr)        
  56.     {
  57.         maskBits->baseAddr=NIL;
  58.          SetRect(&maskBits->bounds,0,0,0,0);
  59.          maskBits->rowBytes=0;
  60.      }
  61.      else        /*    memory was allocated for Mask BitMap ok */
  62.      {
  63.          CalcOffScreen(srcRect,&needed,&rowbytes);
  64.          words=rowbytes/2;
  65.          height=srcRect->bottom - srcRect->top;
  66.          CalcMask(srcBits->baseAddr,maskBits->baseAddr,rowbytes,rowbytes,height,words);
  67.      }
  68. }
  69.